package com.yuninglong.serverb;

import com.yuninglong.serverb.feign.ServerClient;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author yuninglong
 */

@Log4j2
@RestController
@RequestMapping("test")
public class TestController {


    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ServerClient serverClient;

    @GetMapping(value = "/echo")
    public String echo() {
        String get = restTemplate.getForObject("http://server/config/get/", String.class);
        log.info("get1-------------" + get);
        log.info("get2-------------" + serverClient.get());

        return get;
    }


    @GetMapping(value = "/nacos-info")
    public String nacosInfo() {
        log.info("nacosInfo...............");
        String nacosInfo = serverClient.getInfo()+"--"+System.currentTimeMillis();
        log.info("nacosInfo-------------" + nacosInfo);
        return nacosInfo;
    }

    @GetMapping(value = "/nacos-info2")
    public String nacosInfo2() {
        String nacosInfo = null;
        try {
            log.info("nacosInfo...............");
            Thread.sleep(10*1000);
            Assert.isTrue(false,"test.....");
            nacosInfo = serverClient.getInfo()+"--"+System.currentTimeMillis();
            log.info("nacosInfo-------------" + nacosInfo);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return nacosInfo;
    }


}
